package com.skiving.cloud.workflow.config;

import org.camunda.bpm.engine.*;
import org.camunda.bpm.engine.impl.history.HistoryLevel;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

import javax.sql.DataSource;

@Configuration
public class WorkflowConfiguration {
    @Bean
    public ProcessEngine processEngine(@Inject DataSource dataSource) {
        return ProcessEngineConfiguration
                .createStandaloneProcessEngineConfiguration()
                .setDataSource(dataSource)
                .setDatabaseSchemaUpdate("false")
                .setDatabaseType("mysql")
                .setHistory(HistoryLevel.HISTORY_LEVEL_FULL.getName())
                .buildProcessEngine();
    }

    //八大接口
    @Bean
    public RepositoryService repositoryService(@Inject ProcessEngine processEngine){
        return processEngine.getRepositoryService();
    }

    @Bean
    public RuntimeService runtimeService(@Inject ProcessEngine processEngine){
        return processEngine.getRuntimeService();
    }

    @Bean
    public TaskService taskService(@Inject ProcessEngine processEngine){
        return processEngine.getTaskService();
    }

    @Bean
    public HistoryService historyService(@Inject ProcessEngine processEngine){
        return processEngine.getHistoryService();
    }

    @Bean
    public FormService formService(@Inject ProcessEngine processEngine){
        return processEngine.getFormService();
    }

    @Bean
    public IdentityService identityService(@Inject ProcessEngine processEngine){
        return processEngine.getIdentityService();
    }

    @Bean
    public ManagementService managementService(@Inject ProcessEngine processEngine){
        return processEngine.getManagementService();
    }
    //八大接口 end
}
